<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计算属性简写</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <div>
            姓:<input type="text" v-model="firstName"> <br>
            名:<input type="text" v-model="lastName"> <br>
            全名:<span>{{fullName}}</span>
        </div>
    </div>
    <script>

        Vue.config.productionTip = false
        var vm = new Vue({
            el: '#root',
            data: {
                firstName: 'yu',
                lastName: 'xiaoyao'
            },
            methods: {
            },

            //计算属性完整写法
            /* computed: {
                 fullName: {
                     get() {
                         console.log(this);
                         return this.firstName + '-' + this.lastName
                     },
                     set(value) {
                         const arr = value.split('-');
                         this.firstName = arr[0];
                         this.lastName = arr[1];
                     }
                 }
             }*/
            //简写形式必须是没有set方法
            computed: {
                fullName() {
                    console.log(this);
                    return this.firstName + '-' + this.lastName
                }
            }
        });
    </script>
</body>

</html>